package com.cndym.servlet;
/**
 * @author faxc
 * @date 2014-12-25 下午03:51:52
 */
import java.util.List;

import javax.servlet.ServletContext;

import javax.servlet.http.HttpSession;

import javax.servlet.http.HttpSessionEvent;

import javax.servlet.http.HttpSessionListener;

import org.apache.log4j.Logger;

import com.cndym.cache.XMemcachedClientWrapper;
import com.cndym.service.IFillByYYService;
import com.cndym.utils.SpringUtils;

/**

 * @author faxc

 */

public class OnlineUserListener implements HttpSessionListener {
    private Logger logger = Logger.getLogger(getClass());
	XMemcachedClientWrapper memcachedClientWrapper = (XMemcachedClientWrapper) SpringUtils.getBean("xmemcachedClientWrapper");
	 IFillByYYService fillByYYService = (IFillByYYService) SpringUtils.getBean("fillByYYServiceImpl");

    public void sessionCreated(HttpSessionEvent event) {

        

    }

    public void sessionDestroyed(HttpSessionEvent event) {

        HttpSession session = event.getSession();
 
        String userCode = (String) session.getAttribute("userCode");
if(memcachedClientWrapper.get(userCode)==null)
{
	logger.info(userCode +" 过期,在listener中删除数据库");
	fillByYYService.updateBySQL("delete from usercode_token_mapping where user_code=?", new String []{userCode});
	fillByYYService.updateBySQL("delete from TOKEN_USERCODE_MAPPING where user_code=?", new String []{userCode});
	
	
}
else
{
	logger.info(userCode+ "在memcache有值");
}

       

    }

}
